package etc.obu.service.model;

public class ServiceStatus<T> {
    /*操作响应码0(成功),1(失败)*/
    private int serviceCode;
    /*操作结果详情*/
    private String serviceInfo;
    private T   data;

    private  final static int SUCCESS=0;
    private  final static int FAIL=1;

    private ServiceStatus(int serviceCode, String serviceInfo) {
        this.serviceCode = serviceCode;
        this.serviceInfo = serviceInfo;
    }

    private ServiceStatus(int serviceCode, String serviceInfo,T data) {
        this.serviceCode = serviceCode;
        this.serviceInfo = serviceInfo;
        this.data=data;
    }

    public int getServiceCode() {
        return serviceCode;
    }

    public void setServiceCode(int serviceCode) {
        this.serviceCode = serviceCode;
    }

    public String getServiceInfo() {
        return serviceInfo;
    }

    public void setServiceInfo(String serviceInfo) {
        this.serviceInfo = serviceInfo;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ServiceStatus success(String info){
        return new ServiceStatus(SUCCESS,info);
    }

    public static<T> ServiceStatus<T> success(String info,T data){
        return new ServiceStatus<>(SUCCESS, info, data);
    }

    public static ServiceStatus fail(String info){
        return new ServiceStatus(FAIL,info);
    }

    public static<T> ServiceStatus<T> fail(String info,T data){
        return new ServiceStatus<>(FAIL,info,data);
    }
}
